﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //合并按钮
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                FileStream fs1 = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
                FileStream fs2 = new FileStream(textBox2.Text, FileMode.Open, FileAccess.Read);
                FileStream fs3 = new FileStream(@"./Data/text.txt", FileMode.Create, FileAccess.Write);

                StreamReader streamReader1 = new StreamReader(fs1, Encoding.UTF8);
                StreamReader streamReader2 = new StreamReader(fs2, Encoding.UTF8);

                StreamWriter streamWriter = new StreamWriter(fs3, Encoding.UTF8);

                string s1 = streamReader1.ReadToEnd();
                string s2 = streamReader2.ReadToEnd();

                streamWriter.Write(s1);
                streamWriter.WriteLine("");
                streamWriter.Write(s2);

                streamReader1.Close();
                streamReader2.Close();
                streamWriter.Close();
            }
            catch (ArgumentNullException arg)
            {
                Console.WriteLine("不能输入空路径");
            }
            catch (ArgumentException arg)
            {
                Console.WriteLine("输入路径不存在！");
            }




        }

        //选择一
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;
                MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            textBox1.Text = fileDialog.FileName;
        }


        //选择二
        private void btn_select2_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;
                MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            textBox2.Text = fileDialog.FileName;
        }
    }
}
